package com.my.swas.sso.module.cms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.base.Splitter;
import com.my.swas.common.base.ResponseResult;
import com.my.swas.sso.common.base.BaseController;
import com.my.swas.sso.module.cms.dto.CmsArticleDto;
import com.my.swas.sso.module.cms.service.CmsArticleService;
import com.my.swas.sso.module.cms.service.CmsBasicService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description:
 * @author: :MaYong
 */
@Controller
@Slf4j
@RequestMapping("admin/cms/article")
public class CmsArticleController extends BaseController {
    @Resource
    CmsArticleService cmsArticleService;
    @Resource
    CmsBasicService cmsBasicService;


    @ResponseBody
    @PostMapping("list")
    public ResponseResult list(CmsArticleDto cmsArticleDto){
        IPage page = cmsArticleService.articleList(cmsArticleDto);
        return ResponseResult.ok(page);
    }

    @ResponseBody
    @PostMapping("insert")
    public ResponseResult insert(CmsArticleDto cmsArticleDto) {
        cmsArticleService.insert(cmsArticleDto);
        return ResponseResult.ok;
    }

    @ResponseBody
    @PostMapping("update")
    public ResponseResult update(CmsArticleDto cmsArticleDto) {
        cmsArticleService.update(cmsArticleDto);
        return ResponseResult.ok;
    }
    @ResponseBody
    @GetMapping("remove")
    public ResponseResult remove(@RequestParam("ids") String ids){
        List<Long> lists = Splitter.on(",").splitToList(ids).stream()
                .map(s -> Long.valueOf(s))
                .collect(Collectors.toList());
        cmsBasicService.removeByIds(lists);
        return ResponseResult.ok;
    }



}
